#include "Method.h"

const double l = 89;
const double h = 49;
double D = 55;
const double beta = (11.5/180)*PI;
const double A = l*sin(beta);
const double B = l*cos(beta);
double C = (h + 0.5*D)*sin(beta) - 0.5*D*tan(beta);
double E = (h + 0.5*D)*cos(beta) - 0.5*D;

double f(double a){
  double s = sin(a);
  double c = cos(a);
  return A*s*c + B*s*s - C*c - E*s;
}

double df(double a){
  double s = sin(a);
  double c = cos(a);
  return A*c*c - A*s*s + 2*B*s*c + C*s - E*c;
}

int main(int argc, char* argv[]){
  double (*pf)(double) = &f;
  double (*pdf)(double) = &df;
  double result,error = 0;
  Newton<double> NTSolver(50,1e-6,pf,pdf,(33.0/180)*PI);
  result = NTSolver.solve();
  error = (*pf)(result);
  cout << "Problem (a) , Newton's method :" << endl; 
  cout << " alpha = " << result << " = " << (result/PI)*180 << "(degree) , absolute error r = " << error << endl;
  D = 30;
  C = (h + 0.5*D)*sin(beta) - 0.5*D*tan(beta);
  E = (h + 0.5*D)*cos(beta) - 0.5*D;
  result = NTSolver.solve();
  error = (*pf)(result);
  cout << "Problem (b) , Newton's method :" << endl; 
  cout << " alpha = " << result << " = " << (result/PI)*180 << "(degree) , absolute error r = " << error << endl;
  Secant<double> SCSolver(50,1e-6,pf,(33.0/180)*PI,0,1e-8);
  result = SCSolver.solve();
  error = (*pf)(result);
  cout << "Problem (c) , Secant method :" << endl; 
  cout << "With initial 33(degree) and 0(degree), " << endl << "alpha = " <<  result << " = " << (result/PI)*180 <<
  "(degree) , absolute error r = " << error << endl;
  SCSolver.set_init1((-11.4/180)*PI);
  result = SCSolver.solve();
  error = (*pf)(result);
  cout << "With initial 33(degree) and -11.4(degree), " << endl << "alpha = " <<  result << " = " << (result/PI)*180 <<
  "(degree) , absolute error r = " << error << endl;
}
